package com.dushibao.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dushibao.admin.model.Admin;
import com.dushibao.admin.model.Menu;
import com.dushibao.admin.model.SysConfig;

import com.dushibao.admin.mv.DushibaoModelAndView;
import com.dushibao.admin.service.ISysConfigService;
import com.dushibao.admin.vo.request.AdminModelPageRequest;
import com.dushibao.admin.vo.request.MenuModelPageRequest;
import com.dushibao.admin.vo.request.SysConfigModelPageRequest;
import com.dushibao.page.PageImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.List;
import java.util.Arrays;

/**
 *
 * Title: SysConfig.java
 *
 * Description:系统配置 前端控制器
 *
 * Copyright: Copyright: Copyright: Copyright (c) 2021
 *
 * Company: www.dushibao.com
 *
 * @author zqd
 *
 * @date 2021-12-08 11:16:17
 *
 * @version dushibao V1.0
 */
@Controller
public class SysConfigController {

    @Autowired
    ISysConfigService entityService;

    @RequestMapping("/sysconfig/list")
    public ModelAndView list(SysConfigModelPageRequest modelPageRequest){
        ModelAndView mv = new DushibaoModelAndView("/sysconfig/list",modelPageRequest);

        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>();

        if(modelPageRequest.getSysKey()!=null && modelPageRequest.getSysKey().length()>1){
            queryWrapper.like("sys_key",modelPageRequest.getSysKey().trim());
        }

        if(modelPageRequest.getSysValue() !=null && modelPageRequest.getSysValue().length()>1){
            queryWrapper.like("sys_value",modelPageRequest.getSysValue().trim());
        }

        IPage<SysConfig> page = new Page<>(modelPageRequest.getCurrent(),modelPageRequest.getPageSize());
        IPage<SysConfig> iPage = this.entityService.page(page,queryWrapper);

        mv.addObject("iPage",iPage);

        return mv;
    }

    @RequestMapping(value = "/sysconfig/del",method = RequestMethod.POST)
    @ResponseBody
    public Boolean del(@RequestBody List<Long> ids){

        this.entityService.removeByIds(ids);

        return true;
    }

    @RequestMapping("/sysconfig/add")
    public ModelAndView add(Long id){
        ModelAndView mv = new DushibaoModelAndView("/sysconfig/add");

        if(id == null){
            return mv;
        }

        SysConfig obj = this.entityService.getById(id);

        mv.addObject("obj",obj);

        return mv;
    }

}
